package com.sz.demo.constant;

import java.math.BigDecimal;

/**
 * @author Lenovo
 */

public enum PromotionEnum {
    /**
     * 格式：满 X 减 Y
     */
    FULL_100_REDUCE_10(new BigDecimal("100"), new BigDecimal("10")),
    FULL_150_REDUCE_20(new BigDecimal("150"), new BigDecimal("20")),
    /**
     * 无折扣
     */
    NO_PROMOTION(BigDecimal.ZERO, BigDecimal.ZERO);

    /**
     * 满多少
     */
    private final BigDecimal threshold;
    /**
     * 减多少
     */
    private final BigDecimal discount;

    PromotionEnum(BigDecimal threshold, BigDecimal discount) {
        this.threshold = threshold;
        this.discount = discount;
    }

    public BigDecimal getThreshold() {
        return threshold;
    }

    public BigDecimal getDiscount() {
        return discount;
    }

    /**
     * 应用满减：如果金额 >= 满足门槛，返回减免后金额；否则原样返回
     */
    public BigDecimal apply(BigDecimal originalAmount) {
        if (this == NO_PROMOTION) {
            return originalAmount;
        }
        if (originalAmount.compareTo(threshold) >= 0) {
            return originalAmount.subtract(discount);
        }
        return originalAmount;
    }

}
